
const logout = document.querySelector('.logout')
const nav = document.querySelectorAll(".nav>li>a") // 获取一级标签里的a标签
const twoa = document.querySelectorAll('.nav ul a')
const init = document.querySelector('.init') // 初始化按钮

logout.addEventListener('click',function(e){
    if (confirm("确定退出")) {
        localStorage.removeItem("cms")
        location.href="login.html"
    }
    
})

// 遍历a标签并且给a标签绑定点击事件 点击a标签是让下一个ul元素切换类名
nav.forEach(res =>res.addEventListener('click',function(e){
    res.nextElementSibling.classList.toggle("show")
    $(res.nextElementSibling).slideToggle()
}))


// 遍历a 并且给a绑定点击事件 点击当前标签时给之前的标签高亮去除
twoa.forEach(item => item.addEventListener('click',function(e){
    document.querySelector(".nav ul a.active").classList.remove("active")
    this.classList.add('active')
}))

init.addEventListener('click',async function(e){
    const res = await axios({url:'/init/data',
headers:{
    Authorization:localStorage.getItem('cms')
}})
// console.log(res);
    if (res.data.code===0) {
        toastr.success(res.data.message)
    }
})


